package com.qd.common.panda.domain.entity.card;

import com.cdqidi.util.page.BaseQuery;
import com.cdqidi.valid.group.DefaultGroup;
import com.cdqidi.valid.group.DeleteGroup;
import com.cdqidi.valid.group.UpdateGroup;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

/**
 * 发卷计划
 *
 * @author sjk
 */
@EqualsAndHashCode(callSuper = true)
@Getter
@Setter
public class CardPlanDTO extends BaseQuery {

    /**
     * 主键
     */
    @NotBlank(message = "计划ID不能为空", groups = {DeleteGroup.class, UpdateGroup.class})
    @Size(max = 50, message = "计划ID长度不能超过{max}位", groups = {DeleteGroup.class, UpdateGroup.class})
    private String planId;
    /**
     * 计划名称
     */
    @NotBlank(message = "计划名称不能为空", groups = DefaultGroup.class)
    @Size(max = 200, message = "计划名称长度不能超过{max}位", groups = DefaultGroup.class)
    private String planName;
    /**
     * 计划内容
     */
    @Size(max = 500, message = "计划内容长度不能超过{max}位", groups = DefaultGroup.class)
    private String planContent;
    /**
     * 兑换的开始时间
     */
    private String useStartTime;
    /**
     * 兑换的结束时间
     */
    @NotBlank(message = "兑换的结束时间不能为空", groups = DefaultGroup.class)
    private String useEndTime;
    /**
     * 卷有效期
     */
    @NotNull(message = "卷有效期不能为空", groups = DefaultGroup.class)
    private Integer volumeValidity;
    /**
     * 码数量
     */
    @NotNull(message = "码数量不能为空", groups = DefaultGroup.class)
    private Integer allocatedQuantity;
    /**
     * 添加时间
     */
    private LocalDateTime addTime;
    /**
     * 更新时间
     */
    private LocalDateTime updateTime;
    /**
     * 操作人
     */
    @Size(max = 50, message = "操作人长度不能超过{max}位", groups = DefaultGroup.class)
    private String operator;
    /**
     * 操作人显示
     */
    private String operatorDisplay;
    /**
     * 机构ID
     */
    @Size(max = 50, message = "机构ID长度不能超过{max}位", groups = DefaultGroup.class)
    private String orgId;
    /**
     * 机构ID显示
     */
    private String orgIdDisplay;
    /**
     * 第三方券商
     */
    @Size(max = 50, message = "第三方券商长度不能超过{max}位", groups = DefaultGroup.class)
    private String thirdParty;
    /**
     * 第三方券商显示
     */
    private String thirdPartyDisplay;
    /**
     * 是否无限数量
     */
    @NotBlank(message = "是否无线数量不能为空", groups = DefaultGroup.class)
    @Size(max = 100, message = "是否无线数量长度不能超过{max}位", groups = DefaultGroup.class)
    private String infiniteQuantity;
    /**
     * 是否无限数量显示
     */
    private String infiniteQuantityDisplay;
    /**
     * 是否回赠
     */
    @NotBlank(message = "是否回赠不能为空", groups = DefaultGroup.class)
    @Size(max = 100, message = "是否回赠长度不能超过{max}位", groups = DefaultGroup.class)
    private String rebate;
    /**
     * 是否回赠显示
     */
    private String rebateDisplay;
    /**
     * 优惠卷列表
     */
    @Valid
    private List<CardInfoDTO> cardInfoList;
    /**
     * 兑换码
     */
    @JsonIgnore
    private List<String> redeemCodeList;

    @Override
    public void freeData() {
        this.planId = null;
        this.useStartTime = null;
        this.useEndTime = null;
        this.volumeValidity = null;
        this.planName = null;
        this.planContent = null;
        this.allocatedQuantity = null;
        this.addTime = null;
        this.updateTime = null;
        this.operator = null;
        this.operatorDisplay = null;
        this.orgId = null;
        this.orgIdDisplay = null;
        this.thirdParty = null;
        this.thirdPartyDisplay = null;
        this.infiniteQuantity = null;
        this.infiniteQuantityDisplay = null;
        this.rebate = null;
        this.rebateDisplay = null;
        Optional.ofNullable(cardInfoList).ifPresent(List::clear);
        Optional.ofNullable(redeemCodeList).ifPresent(List::clear);
        super.freeData();
    }
}
